package com.one.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;


@Configuration
class MyInterceptorConfig extends WebMvcConfigurationSupport {


    /**
     * 静态资源
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //在windows环境下的图片存放资源路径
        if (!registry.hasMappingForPattern("/doc.html")) {
            registry.addResourceHandler("/doc.html")
                    .addResourceLocations("classpath:/META-INF/resources/");
        }
        if (!registry.hasMappingForPattern("/favicon.ico")) {
            registry.addResourceHandler("/favicon.ico")
                    .addResourceLocations("classpath:/META-INF/resources/");
        }
        if (!registry.hasMappingForPattern("/webjars/**")) {
            registry.addResourceHandler("/webjars/**")
                    .addResourceLocations("classpath:/META-INF/resources/webjars/");
        }
        super.addResourceHandlers(registry);
    }
    /*跨越*/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")/*设置允许跨域的路径*/
                .allowedOrigins("*")/*设置允许跨域的域名*/
                .allowCredentials(true)/*设置允许的证书*/
                .allowedMethods("GET","POST","DELETE","PUT","OPTIONS")/*设置允许跨域的方法*/
                .maxAge(7200);/*设置跨域的最大时间*/
    }
}